#include "homepage.h"
#include "ui_homepage.h"
#include "globalval.h"

HomePage::HomePage(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::HomePage)
{
    ui->setupUi(this);

    //mqtt相关
    MqttHandler *mqtt = new MqttHandler;
    GlobalVal::mqtt = mqtt;


    //哪个界面需要接收Mqtt的消息，就订阅这个信号，然后在自己的界面文件中处理消息
//    QObject::connect(mqtt, SIGNAL(dataUpSignal(QByteArray)),
//                     modbusWig, SLOT(dataUpSlot(QByteArray)));
    //实例化界面
    devdata =new device_data;
    devsearch=new Device_search;
    mtor=new Monitor;
    //将四个界面依次添加到堆栈窗体
    ui->stackedWidget->addWidget(devsearch);
    ui->stackedWidget->addWidget(devdata);
    ui->stackedWidget->addWidget(mtor);
    //连接列表界面和堆栈窗体的信号
    QObject::connect(ui->listWidget, SIGNAL(currentRowChanged(int)),
                     ui->stackedWidget, SLOT(setCurrentIndex(int)));
    mqtt->setHost(QHostAddress(devdata->mqtt_server.addr));
    //mqtt->setHost(QHostAddress("192.168.51.67"));
    mqtt->setPort(1883);
    mqtt->connectToHost();

}

HomePage::~HomePage()
{
    delete ui;
}
